package com.penghe.www.baselibrary.utils

import android.graphics.Bitmap
import java.lang.ref.WeakReference


/**
 * Created by alm on 17-6-1.
 * 图片显示器
 */
class BitmapDisplayer(var bitmap: Bitmap?, var holder: BitmapHolder, imageLoader: ImageLoader) : Runnable {

    /**
     * 图片加载类弱引用
     */
    private val imageLoaderWeakReference: WeakReference<ImageLoader> = WeakReference(imageLoader)

    override fun run() {
        val imageLoader: ImageLoader = imageLoaderWeakReference.get() ?: return
        if (imageLoader.imageViewReused(holder)) {
            return
        }

        if (bitmap != null) {
            holder.imageView.setImageBitmap(bitmap)
        } else {
            holder.imageView.setImageResource(imageLoader.getDefaultDrawable())
        }
    }
}